/*
 * Created on 2006-2-22
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.com.sbell.vss.csg.vap;

import org.dom4j.Element;

import cn.com.sbell.vss.VssConstants;
import cn.com.sbell.vss.VssException;
import cn.com.sbell.vss.csg.vap.bean.GPIODeviceInfo;
import cn.com.sbell.vss.csg.vsclient.VsClient;
import cn.com.sbell.vss.csg.vsclient.util.BeanValidator;
import cn.com.sbell.vss.csg.vsclient.util.PropertiesHolder;

/**
 * @author liang.a.chen
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class SetVsInOutDev extends ProtectedVsCommander {

	protected Element executeCommand(VsClient vsClient, PropertiesHolder holder, Element root) {
		GPIODeviceInfo.ChannelInfo channelInfo = (GPIODeviceInfo.ChannelInfo)holder.populate(new GPIODeviceInfo.ChannelInfo());
		BeanValidator.validateNotNull(
				channelInfo,
				new String[]{
						"channelNumber",
						"state"
				}
		);
		if(holder.getBoolProperty("isInputChannel").booleanValue()){
			channelInfo.setChannelType(GPIODeviceInfo.INPUT);
		}else{
			channelInfo.setChannelType(GPIODeviceInfo.OUTPUT);
		}
		if(!vsClient.setInOutDev(channelInfo)){
			throw new VssException(VssConstants.CODE_SETGPIODEVICE_FAILED);
		}
		return root;
	}
}
